package com.twoGroup.boot.service.imp;


import com.twoGroup.boot.mapper.CommonMapper;
import com.twoGroup.boot.pojo.*;
import com.twoGroup.boot.service.CommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class CommonServiceImpl implements CommonService {
    @Autowired
    private CommonMapper commonMapper;

    @Override
    public Page<Shop> queryShop(String shopName, Integer pageNow, Integer pageSize) {
        Page<Shop> page = new Page<>();
        page.setPageTotalCount(commonMapper.shopsAllCount(shopName));
        page.setPageNow(pageNow);
        page.setPageSize(pageSize);
        page.setPageTotal(page.getPageTotal());
        page.setStart((pageNow-1)*pageSize);
        List<Shop> shops = commonMapper.queryShop(shopName, page.getStart(), pageSize);
        page.setList((ArrayList<Shop>) shops);
        return page;
    }

    @Override
    public Page<GoodsAndShopAndGoodsTypeAndGoodsBrand> queryGoods(String goodsName, Integer pageNow, Integer pageSize) {
        Page<GoodsAndShopAndGoodsTypeAndGoodsBrand> page = new Page<>();
        page.setPageTotalCount(commonMapper.goodsAllCount(goodsName));
        page.setPageNow(pageNow);
        page.setPageSize(pageSize);
        page.setPageTotal(page.getPageTotal());
        page.setStart((pageNow-1)*pageSize);
        List<GoodsAndShopAndGoodsTypeAndGoodsBrand> goods = commonMapper.queryGoods(goodsName, pageNow, pageSize);
        page.setList((ArrayList<GoodsAndShopAndGoodsTypeAndGoodsBrand>) goods);
        return page;
    }

    @Override
    public List<Map<String, Object>> queryForGoodsByBrand(int goodsBrandId) {
        return commonMapper.queryForGoodsByBrand(goodsBrandId);
    }

    @Override
    public List<GoodsBrand> queryForAllGoodsBrand() {
        return commonMapper.queryForAllGoodsBrand();
    }

    @Override
    public List<GoodsType> queryForAllType() {
        return commonMapper.queryForAllType();
    }

    @Override
    public List<Map<String, Object>> queryForGoodsByTypeId(int typeId) {
        return commonMapper.queryForAllGoodsByType(typeId);
    }

    @Override
    public Page<Map<String,Object>> queryForAllByPage(int pageNow, int pageSize) {
        Page<Map<String,Object>> page=new Page<>();
        page.setPageNow(pageNow);
        page.setPageSize(pageSize);
        page.setStart((pageNow-1)*pageSize);
        page.setPageTotalCount(commonMapper.queryForAllCount());
        page.setPageTotal(page.getPageTotal());
        List<Map<String,Object>> list=commonMapper.queryForAllGoodsByPage(page.getStart(),page.getPageSize());
        page.setList((ArrayList<Map<String, Object>>) list);
        return page;
    }
}
